<template>
    <div>
      <form action="javascript:;" method="post" class="loginRegisterFrom">
        <section>
          <label class="label1">
            <p>{{$t("loginRegistration.registration.username")}}</p>
            <input type="text" v-model="inputForm.userName" placeholder=" " required>
            <div class="border"></div>
          </label>
          <label class="label2">
            <p>{{$t("loginRegistration.registration.gender")}}</p>
            <input type="text" v-model="inputForm.userGender" placeholder="" required id="gender">
            <div class="border"></div>
          </label>
          <label class="label3">
            <p>{{$t("loginRegistration.registration.email")}}</p>
            <input type="email" v-model="inputForm.userEmail" placeholder=" "required>
            <div class="border"></div>
          </label>
          <label class="label4">
            <p>{{$t("loginRegistration.registration.password")}}</p>
            <input type="password" v-model="inputForm.userPassword" placeholder=" "required id="password">
            <div class="border"></div>
          </label>
          <label class="label5">
            <p>{{$t("loginRegistration.registration.rePassword")}}</p>
            <input type="password" placeholder=" "required id="againPassword">
            <div class="border"></div>
          </label>
          <button type="submit" id="submit" @click="tips">
            {{$t("loginRegistration.registration.buttonName")}}
          </button>
        </section>
      </form>
    </div>
</template>

<script>
    export default {
        name: "Registration",
        data(){
            return {
                inputForm:{
                    userId:'',
                    userName:'',
                    userGender:'',
                    userNickname:'',
                    userHeadPortrait:'',
                    userPassword:'',
                    userEmail:'',
                    userSign:'',
                    userCreateDate:'',
                    userTag:'',
                    userHandle:'',
                    userHandleDuration:'',
                },
                baseURL:'http://localhost:8081/loginReg/registration/',
            }
        },
        mounted(){
            this.$emit("component","registration")
        },
        methods:{
            tips(){
                let gender = document.getElementById("gender").value
                let password = document.getElementById("password").value
                let againPassword = document.getElementById("againPassword").value
                let tag = 0
                if (gender!="男" && gender != "女"){
                    tag++
                    this.$message.error(this.$t("loginRegistration.registration.genderIllegal"))
                    document.getElementById("submit").form.action = "javascript:;"
                    return
                }
                if (password != againPassword){
                    tag++
                    this.$message.error(this.$t("loginRegistration.registration.twoPasswordNotSame"))
                    document.getElementById("submit").form.action = "javascript:;"
                    return;
                }
                // 没有问题的时候
                if (tag==0){
                    // document.getElementById("submit").form.action = "https://www.baidu.com/"
                    let parameters = JSON.stringify(this.inputForm)
                    this.axios.post(this.baseURL+parameters).then((res)=>{
                        if (res.data==false){
                            //登录验证不通过
                            this.failOpt(this.$t("loginRegistration.registration.registrationFail"))
                        }else {
                            // 登录验证通过
                            // this.$router.push('/loginRegistrationPage/login) // 跳转首页，不带参数
                            // 跳转到首页，并带上登录用户的id
                            this.$router.push({path: '/loginRegistrationPage/login', query: {res:"true01"}})
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t("notify.success"),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t("notify.error"),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .loginRegisterFrom section label {
    display: block;
    margin-bottom: 15px;
    position: relative
  }
  .loginRegisterFrom section label p {
    color: rgb(58, 58, 58);
    margin: 0 0 10px 0;
    font-weight: 600;
    font-size: 12px;
    opacity: .8;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .loginRegisterFrom section label input {
    width: 100%;
    display: block;
    border: 0;
    background: transparent;
    color: rgb(58, 58, 58);
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    padding: 0 0 10px;
    box-sizing: border-box;
    font-weight: 600;

  }

  .loginRegisterFrom section label input:focus~.border {
    transform: scale(1, 1);
  }

  .loginRegisterFrom section label .border {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgb(58, 58, 58);
    transform: scale(0, 1);
    transition: .2s ease;
  }

  .loginRegisterFrom section label:last-child {
    margin-bottom: 0;
  }
  .label1,
  .label2,
  .label3,
  .label4,
  .label5{
    height: 48px;
    transition: 0.2s;
    overflow: hidden;
    /*background-color: tomato;*/
  }
  .loginRegisterFrom section button {
    background: #05a090;
    border: 0;
    width: 100%;
    padding: 10px 0;
    font-weight: 600;
    border-radius: 3px;
    color: rgb(236, 236, 236);
    cursor: pointer;
    letter-spacing: 2px;
    margin-top: 15px;
  }

  .loginRegisterFrom section button:hover {
    background: #009788;
    color: rgb(255, 255, 255);
  }
</style>
